package com.hiultra.archive.controller;

import com.hiultra.archive.domain.ArcEnvironment;
import com.hiultra.archive.service.IArcEnvironmentService;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.page.TableDataInfo;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 环境Controller
 * 
 * @author ls
 * @date 2022-07-28
 */
@Api(tags="环境Controller")
@RestController
@RequestMapping("/environment/environment")
public class ArcEnvironmentController extends BaseController
{
    @Autowired
    private IArcEnvironmentService arcEnvironmentService;

    /**
     * 查询环境列表
     */
    @ApiOperation(value = "查询环境列表", notes = "查询环境列表")
    @PreAuthorize("@ss.hasPermi('environment:environment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArcEnvironment arcEnvironment)
    {
        startPage();
        List<ArcEnvironment> list = arcEnvironmentService.selectArcEnvironmentList(arcEnvironment);
        return getDataTable(list);
    }

    /**
     * 导出环境列表
     */
    @ApiOperation(value = "导出环境列表", notes = "导出环境列表")
    @PreAuthorize("@ss.hasPermi('environment:environment:export')")
    @Log(title = "环境", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcEnvironment arcEnvironment)
    {
        List<ArcEnvironment> list = arcEnvironmentService.selectArcEnvironmentList(arcEnvironment);
        ExcelUtil<ArcEnvironment> util = new ExcelUtil<ArcEnvironment>(ArcEnvironment.class);
        util.exportExcel(response, list, "环境数据");
    }

    /**
     * 获取环境详细信息
     */
    @ApiOperation(value = "获取环境详细信息", notes = "获取环境详细信息")
    @PreAuthorize("@ss.hasPermi('environment:environment:query')")
    @GetMapping(value = "/{environmentId}")
    public AjaxResult getInfo(@PathVariable("environmentId") Long environmentId)
    {
        return AjaxResult.success(arcEnvironmentService.selectArcEnvironmentByEnvironmentId(environmentId));
    }

    /**
     * 新增环境
     */
    @ApiOperation(value = "新增环境", notes = "新增环境")
    @PreAuthorize("@ss.hasPermi('environment:environment:add')")
    @Log(title = "环境", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcEnvironment arcEnvironment)
    {
        return toAjax(arcEnvironmentService.insertArcEnvironment(arcEnvironment));
    }

    /**
     * 修改环境
     */
    @ApiOperation(value = "修改环境", notes = "修改环境")
    @PreAuthorize("@ss.hasPermi('environment:environment:edit')")
    @Log(title = "环境", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcEnvironment arcEnvironment)
    {
        return toAjax(arcEnvironmentService.updateArcEnvironment(arcEnvironment));
    }

    /**
     * 删除环境
     */
    @ApiOperation(value = "删除环境", notes = "删除环境")
    @PreAuthorize("@ss.hasPermi('environment:environment:remove')")
    @Log(title = "环境", businessType = BusinessType.DELETE)
	@DeleteMapping("/{environmentIds}")
    public AjaxResult remove(@PathVariable Long[] environmentIds)
    {
        return toAjax(arcEnvironmentService.deleteArcEnvironmentByEnvironmentIds(environmentIds));
    }
}
